<!--
 * @Author: Bennty
 * @Date: 2024-08-14 09:54:32
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-08-15 10:35:59
 * @Description: 请填写简介
-->
<template>
    <el-dialog v-model="props.visible" title="新增小类信息" @close="handleClose" width="25%">
        <el-form :model="singleCategoryFormData" ref="singleCategoryFormRef">
            <el-form-item label="现有小类信息">
                <el-row>
                    <el-col :span="15">
                        <el-select v-model="selectedSingleCategory" clearable placeholder="请选择">
                            <el-option v-for="item in existedSingleCategory" :key="item.id" :label="item.singleCategoryName" :value="item.id"></el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="2"></el-col>
                    <el-col :span="5">
                        <el-button type="danger" :disabled="!selectedSingleCategory">删除</el-button>
                    </el-col>
                </el-row>
            </el-form-item>
            <el-form-item label="新增小类信息" prop="singleCategoryName">
                <el-row :gutter="8">
                    <el-col :span="16">
                        <el-input v-model="singleCategoryFormData.singleCategoryName" placeholder="输入新增小类的名称"></el-input>
                    </el-col>
                    <el-col :span="1"></el-col>
                    <el-col :span="3">
                        <el-button type="primary" @click="handleSubmit">添加</el-button>
                    </el-col>
                </el-row>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleClose">确 定</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';

const props = defineProps(['visible']);
const emits = defineEmits(['close']);
const singleCategoryFormRef = ref<FormInstance>();
const singleCategoryFormData = ref({
    singleCategoryName: undefined
});
const existedSingleCategory = ref([
    {
        id:1,
        singleCategoryName: '抽屉盒'
    },
    {
        id: 2,
        singleCategoryName: '生日帽'
    }
]);
const selectedSingleCategory = ref<any>();

const handleSubmit = ()=>{
    /** 检测是否有重复的 */
};

const handleClose = ()=>{
    emits('close');
    singleCategoryFormRef.value?.resetFields();
};
</script>

<style lang="scss" scoped>
.dialog-footer{
    display: flex;
    justify-content: center;
}
</style>